<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="./src/vue.js"></script>
    <title>Document</title>
    <style>
      .test {
        width: 100px;
        height: 100px;
        background-color: yellow;
      }
      .v-enter {
        opacity: 0;
      }
      .v-enter-active {
        transition: all 3s;
      }
      .v-enter-to {
        opacity: 1;
      }
      .v-leave {
        opacity: 1;
      }
      .v-leave-active {
        transition: all 3s;
      }
      .v-leave-to {
        opacity: 0;
      }
      .first-enter {
        opacity: 0;
      }
      .first-enter-active {
        transition: all 3s;
      }
      .first-enter-to {
        opacity: 1;
      }
      .first-leave {
        opacity: 1;
      }
      .first-leave-active {
        transition: all 3s;
      }
      .first-leave-to {
        opacity: 0;
      }
      .second-enter {
        opacity: 0;
        transform: translateX(300px);
      }
      .second-enter-active {
        transition: all 3s;
      }
      .second-enter-to {
        opacity: 1;
        transform: translateX(0);
      }
      .second-leave {
        opacity: 1;
        transform: translateX(0);
      }
      .second-leave-active {
        transition: all 3s;
      }
      .second-leave-to {
        opacity: 0;
        transform: translateX(300px);
      }
    </style>
  </head>
  <body>
    <div id="app">
      <transition name="first">
        <div class="test" v-show="show"></div>
      </transition>
      <transition name="second">
        <div class="test" v-show="show"></div>
      </transition>
      <button @click="show=!show">显示/隐藏</button>
    </div>
    <script>
      const vm = new Vue({
        el: "#app",
        data: {
          show: true,
        },
        methods: {},
      });

      // 总结：
      // 通过transition过渡组件，结合内置6个过渡类名实现动画效果。也可以通过name属性自定义类名前缀解决多个transition过渡组件冲突问题。
      // 语法：
      /*
      <transition name="first">
        单组件/元素
      </transition>
      */
    </script>
  </body>
</html>
